#include <UnitTest++.h>
#include <iostream>
#include <stdlib.h>

using namespace std;
using namespace UnitTest;

int globalnewcount = 0;
int tempglobalnewcount = 0;

void* operator new(size_t size) throw (std::bad_alloc)
{
	void* p = malloc(size);
	globalnewcount++;
	return p;
}

void operator delete(void* p) throw()
{
	globalnewcount--;
	free(p);
}

void* operator new[](size_t size) throw (std::bad_alloc)
{
	void* p = malloc(size);
	globalnewcount++;
	return p;
}

void operator delete[](void* p) throw()
{
	globalnewcount--;
	free(p);
}

void StartMemoryLeakTest()
{
	tempglobalnewcount = globalnewcount;
	globalnewcount = 0;
}

int GetCurrentNewCount()
{
	return globalnewcount;
}

int GetNewCountTestResult()
{
	int result = globalnewcount;
	globalnewcount = tempglobalnewcount;
	return result;
}
